<?php
/**
 * @name Reponse
 *
 * LICENSE
 *
 * This source file is subject to the BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.phpxe.com/license/
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to Chaodong.Sheng <scd113@gmail.com> so we can send you a copy immediately.
 *
 * @category   Controller of Scd Framework
 * @package    Scd
 * @copyright  Copyright (c) 2007 PHPXe Web Studio <http://www.phpxe.com>
 * @license    http://framework.phpxe.com/license/
 * @version    $Id: Reponse.php Mon Sep 24 23:54:31 CST 2007 Davy $
 */
include_once("Scd/Controller/Exception.php");
class Scd_Controller_Reponse_Reponse {
	function Scd_Controller_Reponse()
	{
	}
	
	/**
     * Whether or not to render exceptions (off by default)
     *
     * If called with no arguments or a null argument, returns the value of the
     * flag; otherwise, sets it and returns the current value.
     *
     * @param boolean $flag Optional
     * @return boolean
     */
	function renderExceptions($flag = null)
	{
		if (null !== $flag) {
			$this->_renderExceptions = $flag ? true : false;
		}

		return $this->_renderExceptions;
	}

	/**
     * Send the response, including all headers, rendering exceptions if so
     * requested.
     *
     * @return void
     */
	function sendResponse()
	{
		$this->sendHeaders();

		if ($this->isException() && $this->renderExceptions()) {
			$exceptions = '';
			foreach ($this->getException() as $e) {
				$exceptions .= $e->__toString() . "\n";
			}
			echo $exceptions;
			return;
		}

		$this->outputBody();
	}

	/**
     * Magic __toString functionality
     *
     * Proxies to {@link sendResponse()} and returns response value as string
     * using output buffering.
     *
     * @return string
     */
	function __toString()
	{
		ob_start();
		$this->sendResponse();
		return ob_get_clean();
	}
}
?>